import collections


class Solution(object):
    def evalRPN(self, tokens):
        """
        :type tokens: List[str]
        :rtype: int
        """
        stack = collections.deque()
        num = {str(i) for i in range(-200, 201)}
        for item in tokens:
            if item in num:
                stack.append(int(item))
            else:
                num1 = stack.pop()
                num2 = stack.pop()
                if item == '+':
                    stack.append(num1 + num2)
                if item == '*':
                    stack.append(num1 * num2)
                if item == '-':
                    stack.append(num2 - num1)
                if item == '/':
                    stack.append(int(num2 / num1))
        return stack[-1]

data = Solution()
tokens = ["2", "1", "+", "3", "*"]
print(data.evalRPN(tokens))
tokens = ["4","13","5","/","+"]
print(data.evalRPN(tokens))
tokens = ["10","6","9","3","+","-11","*","/","*","17","+","5","+"]
print(data.evalRPN(tokens))